package com.analysis.client;

import com.analysis.enums.ModelChatClientEnum;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.openai.api.OpenAiApi;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import java.util.*;

/**
 * 用于AI曝光量分析
 */
@Component
public class BrandExposureAiChatClient {

    // 根据不同来源，调用不同大模型
    private final Map<String, ChatClient> chatClientMap = new HashMap<>();

    /**
     * 构造函数，注入不同模型的聊天客户端
     */
    public BrandExposureAiChatClient(
            @Qualifier("yuanbaoChatClient") ChatClient yuanbaoChatClient,
            @Qualifier("kimiChatClient") ChatClient kimiChatClient,
            @Qualifier("qwenChatClient") ChatClient qwenChatClient,
            @Qualifier("deepseekChatClient") ChatClient deepseekChatClient,
            @Qualifier("doubaoChatClient") ChatClient doubaoChatClient,
            @Qualifier("baiduChatClient") ChatClient baiduChatClient
    ) {
        // 将每个模型的ChatClient放入Map中
        chatClientMap.put(ModelChatClientEnum.QWEN.getSource(), qwenChatClient);
        chatClientMap.put(ModelChatClientEnum.DEEPSEEK.getSource(), deepseekChatClient);
        chatClientMap.put(ModelChatClientEnum.DOUBAO.getSource(), doubaoChatClient);
        chatClientMap.put(ModelChatClientEnum.KIMI.getSource(), kimiChatClient);

//        chatClientMap.put(ModelChatClientEnum.YUANBAO.getSource(), yuanbaoChatClient);
//        chatClientMap.put(ModelChatClientEnum.BAIDU.getSource(), baiduChatClient);
    }

    /**
     * 根据source获取对应的ChatClient
     */
    public ChatClient getChatClient(String source) {
        ChatClient client = chatClientMap.get(source);
        if (client == null) {
            throw new IllegalArgumentException("未找到source为 '" + source + "' 的ChatClient");
        }
        return client;
    }

    /**
     * 获取所有可用的模型source列表
     */
    public String[] getAvailableSources() {
        return chatClientMap.keySet().toArray(new String[0]);
    }

    /**
     * 检查指定source是否可用
     */
    public boolean isSourceAvailable(String source) {
        return chatClientMap.containsKey(source);
    }

    
}
